﻿namespace MhAdmin.SqlSugar.Extension
{
    /// <summary>
    /// SqlSugar逻辑删除扩展类
    /// </summary>
    public static class SqlSugarLogicalDelete6
    {
        #region 单对象条件删除

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static int FalseDelete<T>(this ISqlSugarClient db, Expression<Func<T, bool>> exp) where T : class, IDeleted, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(exp).ExecuteCommand();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<int> FalseDeleteAsync<T>(this ISqlSugarClient db, Expression<Func<T, bool>> exp) where T : class, IDeleted, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(exp).ExecuteCommandAsync();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static bool FalseDeleteChange<T>(this ISqlSugarClient db, Expression<Func<T, bool>> exp) where T : class, IDeleted, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(exp).ExecuteCommand() > 0;
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<bool> FalseDeleteChangeAsync<T>(this ISqlSugarClient db, Expression<Func<T, bool>> exp) where T : class, IDeleted, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(exp).ExecuteCommandAsync() > 0;
        }

        #endregion 单对象条件删除

        #region 单索引删除

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static int FalseDelete<T>(this ISqlSugarClient db, long id) where T : class, IDeleted, IPrimaryKey, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => x.Id == id).ExecuteCommand();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<int> FalseDeleteAsync<T>(this ISqlSugarClient db, long id) where T : class, IDeleted, IPrimaryKey, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => x.Id == id).ExecuteCommandAsync();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static bool FalseDeleteChange<T>(this ISqlSugarClient db, long id) where T : class, IDeleted, IPrimaryKey, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => x.Id == id).ExecuteCommand() > 0;
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<bool> FalseDeleteChangeAsync<T>(this ISqlSugarClient db, long id) where T : class, IDeleted, IPrimaryKey, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => x.Id == id).ExecuteCommandAsync() > 0;
        }

        #endregion 单索引删除

        #region 集合单索引删除

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static int FalseDelete<T>(this ISqlSugarClient db, List<long> ids) where T : class, IDeleted, IPrimaryKey, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => ids.Contains(x.Id)).ExecuteCommand();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<int> FalseDeleteAsync<T>(this ISqlSugarClient db, List<long> ids) where T : class, IDeleted, IPrimaryKey, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => ids.Contains(x.Id)).ExecuteCommandAsync();
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public static bool FalseDeleteChange<T>(this ISqlSugarClient db, List<long> ids) where T : class, IDeleted, IPrimaryKey, new()
        {
            return db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => ids.Contains(x.Id)).ExecuteCommand() > 0;
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public async static Task<bool> FalseDeleteChangeAsync<T>(this ISqlSugarClient db, List<long> ids) where T : class, IDeleted, IPrimaryKey, new()
        {
            return await db.Updateable<T>().SetColumns(it => it.IsDelete == true).Where(x => ids.Contains(x.Id)).ExecuteCommandAsync() > 0;
        }

        #endregion 集合单索引删除
    }
}